package cooccurrence;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Parse {
	
	public Set<String> parseTxt(String filepath) throws FileNotFoundException{
	    Set<String> result = new HashSet<String>();
	    //Note that FileReader is used, not File, since File is not Closeable
	    File input = new File(filepath);
	    Scanner scanner = new Scanner(new FileReader(input));
	    try {
	        //first use a Scanner to get each line
	        while (scanner.hasNextLine()){
	            String line = scanner.nextLine();
	            result.add(line);
	        }
	    }
	    finally {
	        //ensure the underlying stream is always closed
	        //this only has any effect if the item passed to the Scanner
	        //constructor implements Closeable (which it does in this case).
	        scanner.close();
	    }
	    return result;
	}

}
